<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
  <link rel="stylesheet" href="./css/index.css" />
</head>

<body>
  <img src="./img/header.png" alt="" class="header" />
  <div class="cq-wrap">
    <!-- 导航 -->
    <div class="nav">
      <ul>
        <li><img src="./img/sword.png" alt="" /><span>剑士</span></li>
        <li><img src="./img/knight.png" alt="" /> <span>骑士</span></li>
        <li><img src="./img/Archer.png" alt="" /> <span>弓手</span></li>
        <li><img src="./img/hunter.png" alt="" /> <span>猎人</span></li>
        <li><img src="./img/magic.png" alt="" /> <span>法师</span></li>
        <li><img src="./img/flamen.png" alt="" /> <span>祭司</span></li>
      </ul>
    </div>
    <!-- table -->
    <table class="cq-list">
      <thead>
        <th>勇士</th>
        <th>技能</th>
        <th>武器</th>
      </thead>
      <tbody>
        
      </tbody>
    </table>
  </div>
  <!-- 遮罩层 -->
  <div class="cover" style="display: none">
    <img class="loading" src="./img/loading01.gif" alt="" />
  </div>
  <script src="./js/jquery-1.12.4.min.js"></script>
  <!-- 模板引擎 -->
  <script src="./js/template-web.js"></script>
  <!-- 模板 -->
  <script id="hero" type="text/html">
  {{each data.heros v}}
  <tr>
    <td>
      <img class="icon" src="{{v.heroIcon}}" alt="" />
      <span>
        {{v.heroName}}
      </span>
    </td>
    <td>
      <img class="skill" src="{{v.skillIcon}}" alt="" />
      {{v.skillName}}
    </td>
    <td>
      <img class="weapon" src="{{v.weaponIcon}}" alt="" />
      {{v.weaponName}}
    </td>
  </tr>
  {{/each}}
</script>
  <script>
    $(function(){
      //计时器切换背景图
      setInterval(function(){
          $.ajax({
              url:'https://autumnfish.cn/api/cover/random',
              type:'get',
              dataType:'json',
              success: function(backData){
                $("body").css("backgroundImage","url("+backData.url+")")
              }
          });
      },6000)

      $(".nav li").click(function(){
          //排他替换样式
          $(this).addClass("active").siblings().removeClass();
          let type=$(this).children("span").text().trim();
          
          $.ajax({
              url:'https://autumnfish.cn/api/cq/category',
              type:'get',
              dataType:'json',
              data:{type:type},
              success: function(backData){
                $("table>tbody").html(template("hero",backData));
              }
          });
          //
      })
      $('.nav li:eq(0)').click();

      $("body").on("click",".icon",function(){
          $(".cover").show();
          $.ajax({
              url:'https://autumnfish.cn/api/cq/gif',
              type:'get',
              dataType:'json',
              data:{name:$(this).next().text().trim()},
              success: function(backData){ 
                    $(".cover>img").attr("src",backData.data.skillGif)
              }
          });
      })

      $(".cover").click(function(){
          $(this).fadeOut(function(){
            $(".cover>img").attr("src","./img/loading01.gif");
          })
      })
      
    })
  </script>
</body>

</html>